package cn.tedu.tmall.admin.content.service.impl;

import cn.tedu.tmall.admin.content.dao.persist.repository.IArticleRepository;
import cn.tedu.tmall.admin.content.dao.search.IArticleSearchRepository;
import cn.tedu.tmall.admin.content.service.IArticleService;
import cn.tedu.tmall.common.pojo.po.ArticleSearchPO;
import cn.tedu.tmall.common.pojo.vo.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleServiceImpl implements IArticleService {

    @Autowired
    private IArticleSearchRepository articleSearchRepository;
    @Autowired
    private IArticleRepository articleRepository;

    @Override
    public void rebuildSearch() {
        articleSearchRepository.deleteAll();
        Integer pageNum = 1;
        Integer pageSize = 3;
        Integer maxPage;
        PageData<ArticleSearchPO> pageData;
        do {
            pageData = articleRepository.listSearch(pageNum, pageSize);
            maxPage = pageData.getMaxPage();
            List<ArticleSearchPO> list = pageData.getList();
            articleSearchRepository.saveALl(list);
            pageNum++;
        }while (pageNum <= maxPage);
    }
}
